/*
 * Images.java
 *
 * Created on 16 wrzesie� 2007, 19:30
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.db;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * Entity class Images
 * 
 * @author Krystian
 */
@Entity
@Table(name = "IMAGES",
        uniqueConstraints=
        @UniqueConstraint(columnNames = {"IMG_NAME", "IMG_USR_ID"}))
@NamedQueries( {
        @NamedQuery(name = "Images.findByImgId", query = "SELECT i FROM Images i WHERE i.imgId = :imgId"),
        @NamedQuery(name = "Images.findByImgPhase", query = "SELECT i FROM Images i WHERE i.imgPhase = :imgPhase"),
        @NamedQuery(name = "Images.display", query = "SELECT i FROM Images i WHERE i.imgName = :imgName AND i.user = :user"),
        @NamedQuery(name = "Images.findBySource", query = "SELECT i FROM Images i WHERE i.imgSource = :source")
    })
public class Images implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "IMG_ID", nullable = false)
    private Integer imgId;

    @Column(name = "IMG_PHASE", nullable = false)
    private Integer imgPhase;

    @Column(name = "IMG_SOURCE", nullable=false)
    private String imgSource;

    
    @Column(name = "IMG_NAME", nullable=false)
    private String imgName;
    
    @ManyToOne
    @JoinColumn(name = "IMG_WRK_ID", referencedColumnName = "WRK_ID")
    private Works work;
    
    @ManyToOne
    @JoinColumn(name = "IMG_USR_ID", referencedColumnName = "USR_ID", nullable=false)
    private Users user;
    
    /** Creates a new instance of Images */
    public Images() {
    }

    public Images(Integer imagePhase, String imageSource, String imageName, Works work) {
        this.imgPhase = imagePhase;
        this.imgSource = imageSource;
        this.imgName = imageName;
        this.setWork(work);
    }
    /**
     * Creates a new instance of Images with the specified values.
     * @param imgId the imgId of the Images
     */
    public Images(Integer imgId) {
        this.imgId = imgId;
    }

    /**
     * Gets the imgId of this Images.
     * @return the imgId
     */
    public Integer getImgId() {
        return this.imgId;
    }

    /**
     * Sets the imgId of this Images to the specified value.
     * @param imgId the new imgId
     */
    public void setImgId(Integer imgId) {
        this.imgId = imgId;
    }

    /**
     * Gets the imgPhase of this Images.
     * @return the imgPhase
     */
    public Integer getImgPhase() {
        return this.imgPhase;
    }

    /**
     * Sets the imgPhase of this Images to the specified value.
     * @param imgPhase the new imgPhase
     */
    public void setImgPhase(Integer imgPhase) {
        this.imgPhase = imgPhase;
    }

    /**
     * Gets the imgSource of this Images.
     * @return the imgSource
     */
    public String getImgSource() {
        return this.imgSource;
    }

    /**
     * Sets the imgSource of this Images to the specified value.
     * @param imgSource the new imgSource
     */
    public void setImgSource(String imgSource) {
        this.imgSource = imgSource;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.imgId != null ? this.imgId.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Images.  The result is 
     * <code>true</code> if and only if the argument is not null and is a Images object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Images)) {
            return false;
        }
        Images other = (Images)object;
        if (this.imgId != other.imgId && (this.imgId == null || !this.imgId.equals(other.imgId))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "info.mikrotubula.db.Images[imgId=" + imgId + "]";
    }

    public String getImgName() {
        return imgName;
    }

    public void setImgName(String imgName) {
        this.imgName = imgName;
    }

    public Works getWork() {
        return work;
    }

    public void setWork(Works work) {
        this.work = work;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }
    
}
